﻿using API.Model;
using MD5Hash;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace API.DAL
{
    public class hyDAL
    {
        public hyDAL(DBhp bhp)
        {
            Bhp = bhp;
        }

        public DBhp Bhp { get; }




        public int addlist(hy hy)
        {
            bool xi = Bhp.hies.Any(h => h.name == hy.name);
            if (xi)
            {
                return -1;

            }
            hy.passwrod = hy.passwrod.GetMD5();
            Bhp.hies.Add(hy);
            return Bhp.SaveChanges();



        }


        public hy dllist(string name,string passwrod)
        {

            var xi = Bhp.hies.FirstOrDefault(h => h.name == name);  
            if(xi==null)
            {

                xi = new hy { id = -1 };


                
            }
            else
            {

                if(xi.passwrod != passwrod.GetMD5())
                {

                    xi = new hy { id = -2 };

                }

                
            }

            return xi;

        }



    }
}
